#include <cstdio>
#include <cstring>

struct Node {
    Node* left_child;
    Node* right_child;
    char data;
};

Node* create_node();
Node* build_tree(int start1, int end1, int start2, int end2);
void post_traverse(Node* tree_root);

char str1[30], str2[30];

int main(int argc, char const* argv[])
{
    while (scanf("%s %s", str1, str2) != EOF) {
        int length1 = strlen(str1);
        int length2 = strlen(str2);
        Node* tree_root = build_tree(0, length1 - 1, 0, length2 - 1);
        post_traverse(tree_root);
        printf("\n");
    }
    return 0;
}

Node* create_node()
{
    Node* return_node = new Node;
    return_node->left_child = return_node->right_child = NULL;
    return return_node;
}

Node* build_tree(int start1, int end1, int start2, int end2)
{
    Node* return_node = create_node();
    return_node->data = str1[start1];
    int root_index;
    for (int i = start2; i <= end2; i++) {
        if (str2[i] == str1[start1])
            root_index = i;
    }
    if (root_index != start2)
        return_node->left_child = build_tree(start1 + 1, root_index - start2 + start1, start2, root_index - 1);
    if (root_index != end2)
        return_node->right_child = build_tree(root_index - start2 + start1 + 1, end1, root_index + 1, end2);
    return return_node;
}

void post_traverse(Node* tree_root)
{
    if (tree_root->left_child != NULL)
        post_traverse(tree_root->left_child);
    if (tree_root->right_child != NULL)
        post_traverse(tree_root->right_child);
    printf("%c", tree_root->data);
}